<?php
namespace app\admin\controller;
use think\Controller;
use think\Db;
use app\admin\controller\Base;
class Member extends Base
{
    public function add_member()
    {
        return $this->fetch();
    }

    public function member_list()
    {
        $keyword=input('get.keyword');
		$where="member_name like '%$keyword%'";
	    //总条数
        $count=Db('member')->where($where)->count();
        //每页显示条数
        $pageSize=3;
        //总页数
        $pagenum=ceil($count/$pageSize);
        //当前页
        $page=input('get.page',1);
        //上一页
        $up=$page-1<1?1:$page-1;
        $next=$page+1>$pagenum?$pagenum:$page+1;
        $end=$pagenum;
        //偏移量
        $limit=($page-1)*$pageSize;
        $data['res']=Db('member')->where($where)->limit($limit,$pageSize)->select();
        $data['yema']=array('page'=>$page,'up'=>$up,'next'=>$next,'end'=>$end,'count'=>$count,'pagenum'=>$pagenum,'pageSize'=>$pageSize);
         if(isset($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest'){
         	echo json_encode($data);
         }else{
			$this->assign('data',$data);
			return view('member/member_list');
         }
    }
    public function member_add()
    {
    	$data=input('post.');
    	// var_dump($data);
    	$data['addtime']=date("Y-m-d H:i:s",time());
    	$res=Db('member')->insert($data);
		if($res){
			$this->success('添加会员成功','member/member_list');
		}else{
			$this->error('添加会员失败','member/add_member');
		}
    }
}